<template>
	<!--活动因子 -->
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="134px"
						ref="form"
						label-suffix="："
					>
						<el-row class="p-b-20">
							<el-col :span="24">
								<el-table ref="multipleTable" :data="ruleForm.tableData" tooltip-effect="dark" border>
									<el-table-column label prop="name" align="center" min-width="80"></el-table-column>

									<el-table-column prop="SECSFACT001" label="活动因子" align="center" min-width="120">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.SECSFACT001"
												:prop="'tableData.'+scope.$index+'.SECSFACT001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.SECSFACT001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column prop="SEPROTIN001" label="保护因子" align="center" min-width="120">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.SEPROTIN001"
												:prop="'tableData.'+scope.$index+'.SEPROTIN001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.SEPROTIN001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column prop="SEBRRATE001" label="呼吸速率" align="center" min-width="120">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.SEBRRATE001"
												:prop="'tableData.'+scope.$index+'.SEBRRATE001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.SEBRRATE001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column prop="SESKPFAC001" label="皮肤保护系数" align="center" min-width="120">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.SESKPFAC001"
												:prop="'tableData.'+scope.$index+'.SESKPFAC001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.SESKPFAC001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column prop="SEGSHFAC001" label="地表隐蔽" align="center" min-width="120">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.SEGSHFAC001"
												:prop="'tableData.'+scope.$index+'.SEGSHFAC001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.SEGSHFAC001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
								</el-table>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="24">
								<el-form-item label="再悬浮系数" prop="SERESCON001">
									<el-input
										size="medium"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
										class="mediumForm"
										v-model="ruleForm.SERESCON001"
									></el-input>
								</el-form-item>
								<el-form-item label="再悬浮半衰期" prop="SERESHAF001">
									<el-input
										size="medium"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
										class="mediumForm"
										v-model="ruleForm.SERESHAF001"
									></el-input>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button
						type="primary"
						:disabled="this.basic_Data.OCENDAT1001=='TRUE'"
						:loading="loading"
						@click="submitFun"
					>下一步</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"
export default {
	name: "aboutUs",
	props: {},
	mixins: [commPara],
	components: {
		selectPara,
		FixBottomButton,
		ueditor,
	},

	data() {
		var SECSFACT = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1.0) {
				callback(new Error("输入范围为[0.0，1.0] "))
			} else {
				callback()
			}
		}
		var SERESHAF001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1.0e10) {
				callback(new Error("输入范围为[0.0，1.0E+10] "))
			} else {
				callback()
			}
		}

		return {
			activeTab: "6",

			ruleForm: {
				SERESCON001: 1.0e-4,
				SERESHAF001: 1.82e5,
				tableData: [
					{
						name: "撤离",
						SECSFACT001: "1.0",
						SEPROTIN001: "1.0",
						SEBRRATE001: 2.66e-4,
						SESKPFAC001: "1.0",
						SEGSHFAC001: "0.5",
					},
					{
						name: "正常",
						SECSFACT001: "0.75",
						SEPROTIN001: "0.41",
						SEBRRATE001: 2.66e-4,
						SESKPFAC001: "0.41",
						SEGSHFAC001: "0.33",
					},
					{
						name: "隐蔽",
						SECSFACT001: "0.6",
						SEPROTIN001: "0.33",
						SEBRRATE001: 2.66e-4,
						SESKPFAC001: "0.33",
						SEGSHFAC001: "0.2",
					},
				],
			},
			rules: {
				SECSFACT001: [
					{
						validator: SECSFACT,
						trigger: "change",
					},
				],
				SEPROTIN001: [
					{
						validator: SECSFACT,
						trigger: "change",
					},
				],
				SEBRRATE001: [
					{
						validator: SECSFACT,
						trigger: "change",
					},
				],
				SESKPFAC001: [
					{
						validator: SECSFACT,
						trigger: "change",
					},
				],
				SEGSHFAC001: [
					{
						validator: SECSFACT,
						trigger: "change",
					},
				],
				SERESCON001: [
					{
						validator: SECSFACT,
						trigger: "change",
					},
				],
				SERESHAF001: [
					{
						validator: SERESHAF001,
						trigger: "change",
					},
				],
			},
			loading: false,
		}
	},
	computed: {
		...mapState({
			early_Data: (state) => state.token.early_Data,
			basic_Data: (state) => state.token.basic_Data,
		}),
	},
	mounted() {
		this.setData()
	},
	methods: {
		setData() {
			this.ruleForm.tableData.forEach((item, index) => {
				item.SECSFACT001 = this.early_Data.SECSFACT001[index]?this.early_Data.SECSFACT001[index].toString():item.SECSFACT001
				item.SEPROTIN001 = this.early_Data.SEPROTIN001[index]?this.early_Data.SEPROTIN001[index].toString():item.SEPROTIN001
				item.SEBRRATE001 = this.early_Data.SEBRRATE001[index]?this.early_Data.SEBRRATE001[index].toString():item.SEBRRATE001
				item.SESKPFAC001 = this.early_Data.SESKPFAC001[index]?this.early_Data.SESKPFAC001[index].toString():item.SESKPFAC001
				item.SEGSHFAC001 = this.early_Data.SEGSHFAC001[index]?this.early_Data.SEGSHFAC001[index].toString():item.SEGSHFAC001
			}) 
			this.ruleForm.SERESCON001=this.early_Data.SERESCON001
			this.ruleForm.SERESHAF001=this.early_Data.SERESHAF001 
		},
		submitFun() {
			//保存
			this.$refs.form.validate((valid) => {
				if (valid) { 
					let tempdata = JSON.parse(JSON.stringify(this.early_Data)) 
					tempdata.SECSFACT001 = this.ruleForm.tableData.map(
						(item) => {
							return parseFloat(item.SECSFACT001)
						}
					)
					tempdata.SEPROTIN001 = this.ruleForm.tableData.map(
						(item) => {
							return parseFloat(item.SEPROTIN001)
						}
					)
					tempdata.SEBRRATE001 = this.ruleForm.tableData.map(
						(item) => {
							return parseFloat(item.SEBRRATE001)
						}
					)
					tempdata.SESKPFAC001 = this.ruleForm.tableData.map(
						(item) => {
							return parseFloat(item.SESKPFAC001)
						}
					)
					tempdata.SEGSHFAC001 = this.ruleForm.tableData.map(
						(item) => {
							return parseFloat(item.SEGSHFAC001)
						}
					)
					tempdata.SERESCON001 = parseFloat(this.ruleForm.SERESCON001)
					tempdata.SERESHAF001 = parseFloat(this.ruleForm.SERESHAF001)
					tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_early_Data", tempdata) 
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "ZAOQI",
						submitjson: JSON.stringify(tempdata),
					} 
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => { 
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "保存失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "保存成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch("change_early_showTab", this.activeTab)
				}
			})
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>